package com.sgb.kjwl.view.widget.transport;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.AppQuickMenuPopLayout01Binding;
import com.sgb.kjwl.databinding.AppQuickMenuPopLayout02Binding;
import com.swgk.core.dialog.PopViewHolder;

/**
 * Describe:    快捷菜单弹窗 （报价单位第三视角页面）
 * Author:  yangLei
 * Date:    2021/8/27
 */
public class QuickMenuPopWindow extends PopupWindow implements View.OnClickListener {
    private AppQuickMenuPopLayout01Binding mBinding;
    private AppQuickMenuPopLayout02Binding mBinding2;
    private MenuClickResult clickResult;
    //0——其他视角页面  1——货主视角页面
    private int type;
    private Context mContext;

    public QuickMenuPopWindow(Context context, int type) {
        super(context);
        this.type = type;
        this.mContext = context;
        init();
    }

    //初始化页面
    private void init() {
        PopViewHolder popViewHolder = PopViewHolder.get(mContext, null, popLayout());
        setContentView(popViewHolder.getPop());
        setFocusable(true);
        setOutsideTouchable(true);
        ColorDrawable dw = new ColorDrawable(0000000);
        this.setBackgroundDrawable(dw);
        setAnimationStyle(com.swgk.core.R.style.popwindow_dropdown);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

        if (type == 1) {
            mBinding2 = (AppQuickMenuPopLayout02Binding) popViewHolder.getmBinding();
            mBinding2.setOnClick(this);
        } else {
            mBinding = (AppQuickMenuPopLayout01Binding) popViewHolder.getmBinding();
            mBinding.setOnClick(this);
        }
    }

    protected int popLayout() {
        if (type == 1) {
            return R.layout.app_quick_menu_pop_layout_02;
        } else {
            return R.layout.app_quick_menu_pop_layout_01;
        }
    }

    public MenuClickResult getClickResult() {
        return clickResult;
    }

    public void setClickResult(MenuClickResult clickResult) {
        this.clickResult = clickResult;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.menu_01_ll:
                dismiss();
                if (clickResult != null)
                    clickResult.onResult(0);
                break;

            case R.id.menu_02_ll:
                dismiss();
                if (clickResult != null)
                    clickResult.onResult(1);
                break;

            case R.id.menu_03_ll:
                dismiss();
                if (clickResult != null)
                    clickResult.onResult(2);
                break;

            case R.id.menu_04_ll:
                dismiss();
                if (clickResult != null)
                    clickResult.onResult(3);
                break;

            case R.id.pop_root:
                dismiss();
                break;
        }
    }

    public interface MenuClickResult {
        void onResult(int position);
    }
}
